<?php


namespace app\common\dao\store\product;

use app\common\dao\BaseDao;
use app\common\model\store\product\ProductReplyTemplate;


class ProductReplyTemplateDao extends BaseDao
{


    protected function getModel(): string
    {
        return ProductReplyTemplate::class;
    }


    public function search(array $where)
    {
        return ProductReplyTemplate::getDB()->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
            $query->whereLike('title', "%{$where['keyword']}%");
        })->when(isset($where['lvl']) && $where['lvl'] !== '', function ($query) use ($where) {
            $query->where('lvl', $where['lvl']);
        })->when(isset($where['cate_id']) && $where['cate_id'] !== '' && $where['cate_id'] > 0, function ($query) use ($where) {
            $query->where('cate_id', $where['cate_id']);
        });
    }

    public function insertAll(array $data)
    {
        return ProductReplyTemplate::getDB()->insertAll($data);
    }


    public function exists(int $id)
    {
        return ProductReplyTemplate::getDB()->where($this->getPk(), $id)->count() > 0;
    }


    public function delete(int $id)
    {
        return ProductReplyTemplate::getDB()->where('id', $id)->delete();
    }


}

